<!-- 物料锁定 -->
<template>
  <basic-container>
    <el-tabs type="border-card" v-model="activeName" @tab-click="handleTabClick(activeName)">
      <el-tab-pane label="工单汇总" name="WORK_ORDER">
        <avue-crud
          v-if="activeName === 'WORK_ORDER'"
          ref="crud"
          v-model="form"
          :option="option"
          :table-loading="loading"
          :data="data"
          :page.sync="page"
          :search.sync="search"
          @search-change="searchChange"
          @search-reset="searchReset"
          @selection-change="selectionChange"
          @current-change="currentChange"
          @size-change="sizeChange"
          @refresh-change="refreshChange"
          @on-load="onLoad"
        >
          <template slot="menuLeft">
            <el-button icon="el-icon-view" size="small" type="primary" v-if="permission.productionQueryReport_viewNgDetail" @click="viewDetail">不良明细</el-button>
            <el-button type="warning" size="small" icon="el-icon-download" v-if="permission.productionQueryReport_export" @click="$refs.exportComp.visible = true"
              >导出</el-button
            >
          </template>
        </avue-crud>
      </el-tab-pane>
      <el-tab-pane label="设备汇总" name="EQUIPMENT">
        <avue-crud
          v-if="activeName === 'EQUIPMENT'"
          ref="equipmentCrud"
          v-model="form"
          :option="equipmentOption"
          :table-loading="loading"
          :data="equipmentData"
          :page.sync="page"
          :search.sync="search"
          @search-change="searchChange"
          @search-reset="searchReset"
          @selection-change="selectionChange"
          @current-change="currentChange"
          @size-change="sizeChange"
          @refresh-change="refreshChange"
          @on-load="equipmentOnLoad"
        >
          <template slot="menuLeft">
            <el-button icon="el-icon-view" size="small" type="primary" v-if="permission.productionQueryReport_viewNgDetail" @click="viewDetail">不良明细</el-button>
            <el-button type="warning" size="small" icon="el-icon-download" v-if="permission.productionQueryReport_export" @click="$refs.exportComp.visible = true"
              >导出</el-button
            >
          </template>
        </avue-crud>
      </el-tab-pane>
      <el-tab-pane label="操作人汇总" name="OPERATOR">
        <avue-crud
          v-if="activeName === 'OPERATOR'"
          ref="operatorCrud"
          v-model="form"
          :option="operatorOption"
          :table-loading="loading"
          :data="operatorData"
          :page.sync="page"
          :search.sync="search"
          @search-change="searchChange"
          @search-reset="searchReset"
          @selection-change="selectionChange"
          @current-change="currentChange"
          @size-change="sizeChange"
          @refresh-change="refreshChange"
          @on-load="operatorOnLoad"
        >
          <template slot="menuLeft">
            <el-button icon="el-icon-view" size="small" type="primary" v-if="permission.productionQueryReport_viewNgDetail" @click="viewDetail">不良明细</el-button>
            <el-button type="warning" size="small" icon="el-icon-download" v-if="permission.productionQueryReport_export" @click="$refs.exportComp.visible = true"
              >导出</el-button
            >
          </template>
        </avue-crud>
      </el-tab-pane>
      <el-tab-pane label="产品序列号汇总" name="SN">
        <avue-crud
          v-if="activeName === 'SN'"
          ref="SNCrud"
          v-model="form"
          :option="SNOption"
          :table-loading="loading"
          :data="SNData"
          :page.sync="page"
          :search.sync="search"
          @search-change="searchChange"
          @search-reset="searchReset"
          @selection-change="selectionChange"
          @current-change="currentChange"
          @size-change="sizeChange"
          @refresh-change="refreshChange"
          @on-load="SNOnLoad"
        >
          <template slot="menuLeft">
            <el-button icon="el-icon-view" size="small" type="primary" v-if="permission.productionQueryReport_viewNgDetail" @click="viewDetail">不良明细</el-button>
            <el-button type="warning" size="small" icon="el-icon-download" v-if="permission.productionQueryReport_export" @click="$refs.exportComp.visible = true"
              >导出</el-button
            >
          </template>
        </avue-crud>
      </el-tab-pane>
      <el-tab-pane label="工序汇总" name="ROUTE">
        <avue-crud
          v-if="activeName === 'ROUTE'"
          ref="routeCrud"
          v-model="form"
          :option="routeOption"
          :table-loading="loading"
          :data="routeData"
          :page.sync="page"
          :search.sync="search"
          @search-change="searchChange"
          @search-reset="searchReset"
          @selection-change="selectionChange"
          @current-change="currentChange"
          @size-change="sizeChange"
          @refresh-change="refreshChange"
          @on-load="routeOnLoad"
        >
          <template slot="menuLeft">
            <el-button icon="el-icon-view" size="small" type="primary" v-if="permission.productionQueryReport_viewNgDetail" @click="viewDetail">不良明细</el-button>
            <el-button type="warning" size="small" icon="el-icon-download" v-if="permission.productionQueryReport_export" @click="$refs.exportComp.visible = true"
              >导出</el-button
            >
          </template>
        </avue-crud>
      </el-tab-pane>
      <div style="padding: 0 10px">
        <span>过站总数：{{ overQuantityTotal }}</span
        >&nbsp;&nbsp;&nbsp;&nbsp;
        <span>不良数量：{{ ngQuantityTotal }}</span>
      </div>
    </el-tabs>
    <el-dialog append-to-body title="不良明细" :visible.sync="ngDetailDialog">
      <avue-crud
        v-if="ngDetailDialog"
        ref="ngDetailCrud"
        :option="ngDetailOption"
        :table-loading="ngDetailLoading"
        :data="ngDetailData"
        :page.sync="ngDetailPage"
        @search-change="ngDetailSearchChange"
        @search-reset="ngDetailSearchReset"
        @current-change="ngDetailCurrentChange"
        @size-change="ngDetailSizeChange"
        @refresh-change="ngDetailRefreshChange"
        @on-load="ngDetailRouteOnLoad"
      >
        <template slot="menuLeft">
          <el-button type="warning" size="small" icon="el-icon-download" @click="$refs.ngDetailExportComp.visible = true">导出</el-button>
        </template>
      </avue-crud>
      <export-comp
        ref="ngDetailExportComp"
        page-api-url="mes-abacus/stat-production-query/production-query-report-detail"
        :option="ngDetailOption"
        :page="ngDetailPage"
        :query="ngDetailQuery"
        file-name="生产查询不良明细"
      >
      </export-comp>
    </el-dialog>
    <common-modal-template ref="commonModalTemplate" :option="tableOption" @getSelectedRows="getSelectedRows" :key="timer" @newKey="newKey"></common-modal-template>
    <export-comp
      v-if="this.activeName === 'WORK_ORDER'"
      ref="exportComp"
      page-api-url="mes-abacus/stat-production-query/production-query-report"
      :option="option"
      :page="page"
      :query="query"
      file-name="生产查询工单汇总"
    >
    </export-comp>
    <export-comp
      v-if="this.activeName === 'EQUIPMENT'"
      ref="exportComp"
      page-api-url="mes-abacus/stat-production-query/production-query-report"
      :option="equipmentOption"
      :page="page"
      :query="query"
      file-name="生产查询设备汇总"
    >
    </export-comp>
    <export-comp
      v-if="this.activeName === 'OPERATOR'"
      ref="exportComp"
      page-api-url="mes-abacus/stat-production-query/production-query-report"
      :option="operatorOption"
      :page="page"
      :query="query"
      file-name="生产查询人员汇总"
    >
    </export-comp>
    <export-comp
      v-if="this.activeName === 'SN'"
      ref="exportComp"
      page-api-url="mes-abacus/stat-production-query/production-query-report"
      :option="SNOption"
      :page="page"
      :query="query"
      file-name="生产查询天汇总"
    >
    </export-comp>
    <export-comp
      v-if="this.activeName === 'ROUTE'"
      ref="exportComp"
      page-api-url="mes-abacus/stat-production-query/production-query-report"
      :option="routeOption"
      :page="page"
      :query="query"
      file-name="生产查询工序汇总"
    >
    </export-comp>
  </basic-container>
</template>
<script>
import CommonModalTemplate from '@/components/common-modal-template/common-modal-template.vue';
import { getList, getTotal, getReportDetail } from '@/api/product/production-query-report';
import { mapGetters } from 'vuex';
import exportComp from '@/components/export-comp';
export default {
  name: 'partLock',
  components: {
    CommonModalTemplate,
    exportComp
  },
  data() {
    return {
      rowData: {},
      activeName: '',
      viewDialog: false,
      option: {
        height: 'calc(100vh - 538px)',
        calcHeight: 30,
        searchShow: true,
        searchSpan: 5,
        searchMenuSpan: 5,
        border: true,
        index: true,
        selection: true,
        dialogClickModal: false,
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        menu: false,
        tip: false,
        indexLabel: '序号',
        column: [
          {
            label: '工单号',
            prop: 'workOrderNo',
            width: 150,
            search: true,
            type: 'search',
            appendClick: () => {
              this.openWorkOrderModal();
            }
          },
          {
            label: '工单数量',
            prop: 'workOrderQuantity',
            width: 150
          },
          {
            label: '产品型号',
            search: true,
            prop: 'partModel'
          },
          {
            label: '过站数量',
            prop: 'overQuantity'
          },
          {
            label: '不良数据',
            prop: 'ngQuantity',
            width: 150
          },
          {
            label: '日期时间',
            prop: 'statisticDate',
            search: true,
            searchSpan: 6,
            searchType: 'datetimerange',
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间',
            searchLabelWidth: 90,
            searchRules: [
              {
                required: true,
                message: '请选择日期时间',
                trigger: 'blur'
              }
            ]
          }
        ]
      },
      loading: true,
      data: [],
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      form: {},
      query: {},
      search: {},
      selectionList: [],
      modalName: '',
      tableOption: {},
      timer: new Date().getTime(), //不同内容使用同一个模态框结构，key值不同需要重新请求渲染数据，否则会请求到上一个使用的数据内容
      equipmentOption: {
        height: 'calc(100vh - 538px)',
        calcHeight: 30,
        searchShow: true,
        searchSpan: 5,
        searchMenuSpan: 3,
        border: true,
        index: true,
        selection: true,
        dialogClickModal: false,
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        menu: false,
        tip: false,
        indexLabel: '序号',
        column: [
          {
            label: '工单号',
            prop: 'workOrderNo',
            search: true,
            type: 'search',
            appendClick: () => {
              this.openWorkOrderModal();
            }
          },
          {
            label: '工单数量',
            prop: 'workOrderQuantity'
          },
          {
            label: '产品型号',
            search: true,
            prop: 'partModel'
          },
          {
            label: '过站数量',
            prop: 'overQuantity'
          },
          {
            label: '不良数据',
            prop: 'ngQuantity'
          },
          {
            label: '设备编码',
            prop: 'equipmentCode',
            search: true
          },
          {
            label: '操作员',
            prop: 'operator'
          },
          {
            label: '日期时间',
            prop: 'statisticDate',
            search: true,
            searchSpan: 6,
            searchType: 'datetimerange',
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间',
            searchLabelWidth: 90,
            searchRules: [
              {
                required: true,
                message: '请选择日期时间',
                trigger: 'blur'
              }
            ]
          }
        ]
      },
      equipmentData: [],
      operatorOption: {
        height: 'calc(100vh - 538px)',
        calcHeight: 30,
        searchShow: true,
        searchSpan: 5,
        searchMenuSpan: 3,
        border: true,
        index: true,
        selection: true,
        dialogClickModal: false,
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        menu: false,
        tip: false,
        indexLabel: '序号',
        column: [
          {
            label: '工单号',
            prop: 'workOrderNo',
            search: true,
            type: 'search',
            appendClick: () => {
              this.openWorkOrderModal();
            }
          },
          {
            label: '工单数量',
            prop: 'workOrderQuantity'
          },
          {
            label: '产品型号',
            search: true,
            prop: 'partModel'
          },
          {
            label: '过站数量',
            prop: 'overQuantity'
          },
          {
            label: '不良数据',
            prop: 'ngQuantity'
          },
          {
            label: '操作员',
            prop: 'operator',
            search: true
          },
          {
            label: '日期时间',
            prop: 'statisticDate',
            search: true,
            searchSpan: 6,
            searchType: 'datetimerange',
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间',
            searchLabelWidth: 90,
            searchRules: [
              {
                required: true,
                message: '请选择日期时间',
                trigger: 'blur'
              }
            ]
          }
        ]
      },
      operatorData: [],
      SNOption: {
        height: 'calc(100vh - 538px)',
        calcHeight: 30,
        searchShow: true,
        searchSpan: 5,
        searchMenuSpan: 3,
        border: true,
        index: true,
        selection: true,
        dialogClickModal: false,
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        menu: false,
        tip: false,
        indexLabel: '序号',
        column: [
          {
            label: '工单号',
            prop: 'workOrderNo',
            search: true,
            type: 'search',
            appendClick: () => {
              this.openWorkOrderModal();
            }
          },
          {
            label: '工单数量',
            prop: 'workOrderQuantity'
          },
          {
            label: '产品型号',
            search: true,
            prop: 'partModel'
          },
          {
            label: '产品SN',
            search: true,
            prop: 'sn'
          },
          {
            label: '过站数量',
            prop: 'overQuantity'
          },
          {
            label: '不良数据',
            prop: 'ngQuantity'
          },
          {
            label: '操作员',
            prop: 'operator'
          },
          {
            label: '日期时间',
            prop: 'statisticDate',
            search: true,
            searchSpan: 6,
            searchType: 'datetimerange',
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间',
            searchLabelWidth: 90,
            searchRules: [
              {
                required: true,
                message: '请选择日期时间',
                trigger: 'blur'
              }
            ]
          }
        ]
      },
      SNData: [],
      routeOption: {
        height: 'calc(100vh - 538px)',
        calcHeight: 30,
        searchShow: true,
        searchSpan: 5,
        searchMenuSpan: 3,
        border: true,
        index: true,
        selection: true,
        dialogClickModal: false,
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        menu: false,
        tip: false,
        indexLabel: '序号',
        column: [
          {
            label: '工单号',
            prop: 'workOrderNo',
            search: true,
            type: 'search',
            appendClick: () => {
              this.openWorkOrderModal();
            }
          },
          {
            label: '工单数量',
            prop: 'workOrderQuantity'
          },
          {
            label: '产品型号',
            search: true,
            prop: 'partModel'
          },
          {
            label: '工序',
            prop: 'routeName',
            search: true,
            type: 'select',
            dicUrl: '/api/mes-product/apaasworkstation/workstation/list',
            props: {
              label: 'name',
              value: 'name'
            }
          },
          {
            label: '过站数量',
            prop: 'overQuantity'
          },
          {
            label: '不良数据',
            prop: 'ngQuantity'
          },
          {
            label: '操作员',
            prop: 'operator'
          },
          {
            label: '日期时间',
            prop: 'statisticDate',
            search: true,
            searchSpan: 6,
            searchType: 'datetimerange',
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间',
            searchLabelWidth: 90,
            searchRules: [
              {
                required: true,
                message: '请选择日期时间',
                trigger: 'blur'
              }
            ]
          }
        ]
      },
      routeData: [],
      ngQuantityTotal: 0,
      overQuantityTotal: 0,
      ngDetailDialog: false,
      ngDetailOption: {
        height: 500,
        calcHeight: 30,
        searchShow: true,
        searchSpan: 6,
        searchMenuSpan: 6,
        border: true,
        index: true,
        selection: true,
        dialogClickModal: false,
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        menu: false,
        tip: false,
        indexLabel: '序号',
        column: [
          {
            label: '不良SN',
            prop: 'sn',
            search: true
          },
          {
            label: '过站时间',
            prop: 'transactionTime',
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss'
          }
        ]
      },
      ngDetailLoading: false,
      ngDetailData: [],
      ngDetailQuery: {},
      ngDetailPage: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      }
    };
  },
  computed: {
    ...mapGetters(['permission'])
  },
  watch: {
    activeName(val) {
      if (val === 'WORK_ORDER' || val == 'EQUIPMENT' || val == 'OPERATOR' || val == 'SN' || val == 'ROUTE') {
        this.$nextTick(() => {
          this.$structuralSplit();
        });
      }
    }
  },
  mounted() {
    this.activeName = 'WORK_ORDER';
    let startDate = this.$moment(new Date()).subtract(6, 'days').format('YYYY-MM-DD');
    let endDate = this.$moment(new Date()).format('YYYY-MM-DD');
    this.$set(this.search, 'statisticDate', [startDate, endDate]);
    this.query.statisticDate = this.search.statisticDate;
  },
  methods: {
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      switch (this.activeName) {
        case 'WORK_ORDER':
          this.onLoad(this.page, params);
          break;
        case 'EQUIPMENT':
          this.equipmentOnLoad(this.page, params);
          break;
        case 'OPERATOR':
          this.operatorOnLoad(this.page, params);
          break;
        case 'SN':
          this.SNOnLoad(this.page, params);
          break;
        case 'ROUTE':
          this.routeOnLoad(this.page, params);
          break;
        default:
          break;
      }
      done();
    },
    searchReset() {
      this.query = {};
      let startDate = this.$moment(new Date()).subtract(6, 'days').format('YYYY-MM-DD');
      let endDate = this.$moment(new Date()).format('YYYY-MM-DD');
      this.$set(this.search, 'statisticDate', [startDate, endDate]);
      this.query.statisticDate = this.search.statisticDate;
      switch (this.activeName) {
        case 'WORK_ORDER':
          this.onLoad(this.page);
          break;
        case 'EQUIPMENT':
          this.equipmentOnLoad(this.page);
          break;
        case 'OPERATOR':
          this.operatorOnLoad(this.page);
          break;
        case 'SN':
          this.SNOnLoad(this.page);
          break;
        case 'ROUTE':
          this.routeOnLoad(this.page);
          break;
        default:
          break;
      }
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear(activeName) {
      this.selectionList = [];
      switch (activeName) {
        case 'WORK_ORDER':
          this.$refs.curd.toggleSelection();
          break;
        case 'EQUIPMENT':
          this.$refs.equipmentCrud.toggleSelection();
          break;
        case 'OPERATOR':
          this.$refs.operatorCrud.toggleSelection();
          break;
        case 'SN':
          this.$refs.SNCrud.toggleSelection();
          break;
        case 'ROUTE':
          this.$refs.routeCrud.toggleSelection();
          break;
        default:
          break;
      }
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      this.query['statisticType'] = this.activeName;
      if (this.search.statisticDate) {
        this.query.startDate = this.$moment(this.search.statisticDate[0]).format('YYYY-MM-DD');
        this.query.endDate = this.$moment(this.search.statisticDate[1]).format('YYYY-MM-DD');
      }
      delete this.query.statisticDate;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.getReport(page.currentPage, page.pageSize, Object.assign(params, this.query));
        this.loading = false;
        this.selectionClear();
      });
    },
    equipmentOnLoad(page, params = {}) {
      this.loading = true;
      this.query['statisticType'] = this.activeName;
      if (this.search.statisticDate) {
        this.query.startDate = this.$moment(this.search.statisticDate[0]).format('YYYY-MM-DD');
        this.query.endDate = this.$moment(this.search.statisticDate[1]).format('YYYY-MM-DD');
      }
      delete this.query.statisticDate;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.equipmentData = data.records;
        this.getReport(page.currentPage, page.pageSize, Object.assign(params, this.query));
        this.loading = false;
        this.selectionClear();
      });
    },
    operatorOnLoad(page, params = {}) {
      this.loading = true;
      this.query['statisticType'] = this.activeName;
      if (this.search.statisticDate) {
        this.query.startDate = this.$moment(this.search.statisticDate[0]).format('YYYY-MM-DD');
        this.query.endDate = this.$moment(this.search.statisticDate[1]).format('YYYY-MM-DD');
      }
      delete this.query.statisticDate;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.operatorData = data.records;
        this.getReport(page.currentPage, page.pageSize, Object.assign(params, this.query));
        this.loading = false;
        this.selectionClear();
      });
    },
    SNOnLoad(page, params = {}) {
      this.loading = true;
      this.query['statisticType'] = this.activeName;
      if (this.search.statisticDate) {
        this.query.startDate = this.$moment(this.search.statisticDate[0]).format('YYYY-MM-DD');
        this.query.endDate = this.$moment(this.search.statisticDate[1]).format('YYYY-MM-DD');
      }
      delete this.query.statisticDate;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.SNData = data.records;
        this.getReport(page.currentPage, page.pageSize, Object.assign(params, this.query));
        this.loading = false;
        this.selectionClear();
      });
    },
    routeOnLoad(page, params = {}) {
      this.loading = true;
      this.query['statisticType'] = this.activeName;
      if (this.search.statisticDate) {
        this.query.startDate = this.$moment(this.search.statisticDate[0]).format('YYYY-MM-DD');
        this.query.endDate = this.$moment(this.search.statisticDate[1]).format('YYYY-MM-DD');
      }
      delete this.query.statisticDate;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.routeData = data.records;
        this.getReport(page.currentPage, page.pageSize, Object.assign(params, this.query));
        this.loading = false;
        this.selectionClear();
      });
    },
    getReport(currentPage, pageSize, params) {
      getTotal(currentPage, pageSize, params).then((res) => {
        this.ngQuantityTotal = this._get(res, 'data.data.ngQuantity', 0);
        this.overQuantityTotal = this._get(res, 'data.data.overQuantity', 0);
      });
    },
    /**
     * 打开工单号选择模态框
     */
    openWorkOrderModal() {
      this.$refs.commonModalTemplate.showModal();
      this.modalName = 'workOrderModal';
      this.tableOption = {
        modalTitle: '选择工单号（双击进行选择）',
        url: '/api/mes-product/work-order/page?workOrderStatus=3',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '生产订单',
            prop: 'productionOrderNo',
            search: true,
            searchType: 'input',
            type: 'search'
          },
          {
            label: '生产工单',
            prop: 'orderNo',
            search: true
          },
          {
            label: '工单类型',
            prop: 'orderType',
            type: 'select',
            rules: [
              {
                required: true,
                message: '请选择工单类型',
                trigger: 'change'
              }
            ],
            dicUrl: '/api/blade-system/dict/dictionary?code=order_type',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '工单数量',
            prop: 'planQuantity',
            type: 'number',
            minRows: 1
          },
          {
            label: '产品编码',
            prop: 'partNo',
            search: true,
            searchType: 'input',
            type: 'search'
          },
          {
            label: '产品名称',
            prop: 'partName',
            search: true
          },
          {
            label: 'BOM版本',
            prop: 'bomVersion',
            type: 'search'
          },
          {
            label: '派工产线',
            prop: 'productionLineName',
            search: true,
            searchType: 'input',
            type: 'search'
          },
          {
            label: '计划开始时间',
            prop: 'planStartDate',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss'
          },
          {
            label: '计划结束时间',
            prop: 'planEndDate',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss'
          },
          {
            label: '制定人',
            prop: 'creatorName',
            disabled: true
          },
          {
            label: '状态',
            prop: 'statusDesc',
            type: 'select',
            search: true,
            dicData: status
          },
          {
            label: '备注',
            prop: 'remark',
            type: 'textarea'
          }
        ]
      };
    },
    // 获取选择的模态框行数据
    getSelectedRows(rowData) {
      switch (this.modalName) {
        case 'workOrderModal':
          this.search.workOrderNo = this._get(rowData, 'orderNo', '');
          break;
        default:
          break;
      }
    },
    // 重新加载公用表格弹窗组件
    newKey() {
      this.timer = new Date().getTime();
    },
    /**
     * tabs点击事件
     */
    handleTabClick(activeName) {
      this.activeName = activeName;
      this.selectionList = [];
      this.search = {};
      this.query = {};
      this.page = {
        pageSize: 20,
        currentPage: 1,
        total: 0
      };
      let startDate = this.$moment(new Date()).subtract(6, 'days').format('YYYY-MM-DD');
      let endDate = this.$moment(new Date()).format('YYYY-MM-DD');
      this.$set(this.search, 'statisticDate', [startDate, endDate]);
      this.query.statisticDate = this.search.statisticDate;
    },
    viewDetail() {
      if (!this.query.startDate) {
        this.$message.warning('日期时间不能为空！');
        return;
      }
      this.ngDetailDialog = true;
      //   this.ngDetailRouteOnLoad(this.ngDetailPage);
    },
    ngDetailSearchChange(params, done) {
      this.ngDetailQuery = params;
      this.ngDetailPage.currentPage = 1;
      this.ngDetailRouteOnLoad(this.ngDetailPage);
      done();
    },
    ngDetailSearchReset() {
      this.ngDetailQuery = {};
      this.ngDetailRouteOnLoad(this.ngDetailPage);
    },
    ngDetailCurrentChange(currentPage) {
      this.ngDetailPage.currentPage = currentPage;
    },
    ngDetailSizeChange(pageSize) {
      this.ngDetailPage.pageSize = pageSize;
    },
    ngDetailRefreshChange() {
      this.ngDetailRouteOnLoad(this.ngDetailPage, this.ngDetailQuery);
    },
    ngDetailRouteOnLoad(page, params = {}) {
      this.ngDetailLoading = true;
      this.ngDetailQuery['statisticType'] = this.activeName;
      this.ngDetailQuery.startDate = this.query.startDate;
      this.ngDetailQuery.endDate = this.query.endDate;
      getReportDetail(page.currentPage, page.pageSize, Object.assign(params, this.query, this.ngDetailQuery)).then((res) => {
        const data = res.data.data;
        this.ngDetailPage.total = data.total;
        this.ngDetailData = data.records;
        this.ngDetailLoading = false;
      });
    }
  }
};
</script>
<style scoped>
::v-deep .el-tabs__item {
  color: #606266 !important;
  font-weight: bold;
}

::v-deep .el-table {
  margin-bottom: 10px;
}
.tdStyle {
  background: #fafafa;
  font-weight: 700;
  color: #909399;
  text-align: right;
  width: auto;
  padding-right: 20px;
  white-space: nowrap;
}
td {
  padding: 5px;
  border: 1px solid #ebeef5;
}
.detail-title {
  font-weight: bold;
  font-size: 14px;
  margin: 10px 0;
}
</style>
